




function Hall_View()
{
	
}






function Hall_Info(owner)
{
	Fact_Info.apply(this, arguments);
	//
	this.owner = owner;
	// 
	this.ui = new Can_UI();
	
}
extend_usemid(Hall_Info, Fact_Info);

/**
 * 初始化一切绘图需要的信息
 */
Hall_Info.prototype.init = function()
{
	this.ui.datas["user_list"] = new UI_Normal(1, "user_list",
			"media/images/ui/hall/user_list_1.jpg", new Position_Normal(755, 240, 164,
					340));
}


function Hall_Base(a_id, a_factid, a_context)
{
	Fact_Scene.apply(this, arguments);
	this.type = null;
	// 房间数
	this.room_amount = null;
	// 
	this.room_size = null;
	// 当前用户数
	this.user_amount = null;
	
	this.user_size = null;
	// 上下文
	this.context = a_context;
	// 房间
	this.rooms = new Can_Room();
	// 静态 界面的配置
	this.view = new ViewConf_Hall();
	//
	this.fact_info = new Hall_Info(this);
}
extend_usemid(Hall_Base, Fact_Scene);


/**
 * 初始化
 */
Hall_Base.prototype.init = function(a_context, a_pro)
{
	Fact_Scene.prototype.init.apply(this, arguments);
	
	this.context = a_context;
	// 设置卧底
	this.intern(this.context, "hall");
	// 清屏
	this.context.clean();
	// 赋值
	this.parseFromPro(a_pro);
	// 静态界面配置与的动态数据关联
	this.view.facts.datas["data_users_avatar"].relevant(this.users);
	this.view.facts.datas["data_users_nickname"].relevant(this.users);
	this.view.facts.datas["data_rooms"].relevant(this.rooms);
	//
	console.log(this.view.facts.datas["data_users_avatar"]);
	console.log("--分割线--");
	
	this.run();
}

//
//
//
//*** 在做进入房间 搞通之,add update地方有问题初始化hall是addroom  初始化room是updateroom
//
//
//
//-----------------draw-------

Hall_Base.prototype.run = function()
{
	var _time = 1;
	var _this = this;
//	_this.view.draw();
	this.timer = setInterval(function()
	{
		if(_this.onoff)
		{
			_this.view.draw();
		}
	}, _time);
}

// -----------------draw-------

/**
 * 进入房间
 */
Hall_Base.prototype.joinRoom = function(aRoom)
{
	// 确认房间可以进入才进入
	if(aRoom != undefined && aRoom != null)
	{
		// 关掉开关
		this.turn("off");
		// 关掉循环
		this.stopInterval();
		// 清屏
		this.context.clean();
		var _room_number = aRoom["room_number"];
		this.rooms.updateData("room_number", _room_number, aRoom);
		aRoom.init(this.context);
	}
}

/**
 * 点击事件捕获 self是canvas
 */
Hall_Base.prototype.onClick = function(evt, attach)
{
	var _target_unit = this.findSelect(evt);
	var _target = _target_unit.link;
	alert("选中：" + _target["fact_id"] + " " + _target["object_type"]);

	switch (_target["object_type"])
	{
	// ui
	case 'UI_Normal':
		switch (_target["fact_id"])
		{
		case 'user_list':
			alert("用户列表框体");
			break;
		default:
			break;
		}
		break;
	case 'Room_Normal':	
		alert("进入：" + _target["room_name"] + " " + _target["room_number"]);
		var _pro_joinroom = new Pro_JoinRoom(_target["room_number"]);
		this.context.send(_pro_joinroom);
		break;
	default:
		break;
	}
}
/**
 * onRecv
 */
Hall_Base.prototype.onRecv = function(msg)
{
	Fact_Scene.prototype.onRecv.apply(this, [msg]);
//	log(msg.data, "browser");
	var parsed = JSON.parse(msg.data);
	alert("on Hall Recv:" + parsed.name + "||" + msg.data);
	switch (parsed.pro_id)
	{
	// 进入房间
	case '1054':
		var _room = proToObj(parsed["room"]);
		this.joinRoom(_room);
		break;
	case 'error':
		alert("error");
		break;
	default:
		break;
	}
}

// ////////////////////////////////////////////
// ////////////////////////////////////////////
// ////////////////////////////////////////////
// ////////////////////////////////////////////

/**
 * 普通对象
 */
function Hall_Normal(a_id, a_factid)
{
	Hall_Base.apply(this, [a_id, a_factid]);
}
extend_usemid(Hall_Normal, Hall_Base);



